package com.example.demo.service.thread;

import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Description: TODO
 * @Author: kangyang
 * @DateTime: 2024/10/15 16:00
 **/
public class SynchronizeRejectPolicy implements RejectedExecutionHandler {
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        try {
            executor.getQueue().put(r);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RejectedExecutionException("Task " + r.toString() + " rejected from " + executor.toString(), e);        }
    }
}
